package com.itsu.vtalk.vo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author suben
 * @createtime 2020/6/21 10:08
 **/
public enum RestEntity {
    EMPTY("", ""),
    UNEXPECTED_ERROR("IE0001", "服务器内部错误"),
    DEFAULT_ERROR("SE0001", "系统繁忙"),
    LOGIN_ERROR("LG0001", "登录失败"),
    LOGIN_AUTH_ERROR("LG0002", "认证失败"),
    ACCOUNT_ERROR("AC0001", "账户异常"),

    OK_BASE("200", "success");

    private String returnCode;

    private String returnMsg;

    private Object data;

    private void setReturnCode(String returnCode) {
        this.returnCode = returnCode;
    }

    private void setReturnMsg(String returnMsg) {
        this.returnMsg = returnMsg;
    }

    private void setData(Object data) {
        this.data = data;
    }

    public String getReturnCode() {
        return returnCode;
    }

    public String getReturnMsg() {
        return returnMsg;
    }

    public Object getData() {
        return data;
    }

    RestEntity(String returnCode, String returnMsg) {
        this.returnCode = returnCode;
        this.returnMsg = returnMsg;
    }

    RestEntity(String returnCode, String returnMsg, Object data) {
        this.returnCode = returnCode;
        this.returnMsg = returnMsg;
        this.data = data;
    }

    RestEntity() {
    }

    public Map<String, Object> tansfor2Map() {
        Map<String, Object> map = new HashMap<>();
        map.put("returnCode", this.getReturnCode());
        map.put("returnMsg", this.getReturnMsg());
        map.put("data", this.getData());
        return map;
    }

    public static RestEntityBuilder build() {
        return new RestEntityBuilder();
    }

    public static class RestEntityBuilder {

        private RestEntity restEntity = RestEntity.EMPTY;

        public RestEntityBuilder withReturnCode(String returnCode) {
            restEntity.setReturnCode(returnCode);
            return this;
        }

        public RestEntityBuilder withReturnMsg(String returnMsg) {
            restEntity.setReturnMsg(returnMsg);
            return this;
        }

        public RestEntityBuilder withData(Object data) {
            restEntity.setData(data);
            return this;
        }

        public RestEntity create(){
            return this.restEntity;
        }
    }
}
